package com.ptu.servlet;

import com.ptu.entity.ExpImage;
import com.ptu.service.ExpImageService;
import com.ptu.service.impl.ExpImageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 */
@WebServlet("/ptu/ExpImageServlet")
public class ExpImageServlet extends BaseServlet {

    private ExpImageService imageService = new ExpImageServiceImpl();

    // 显示报销单图片
    protected void showImages(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String realPath = req.getServletContext().getRealPath("imgs");

        String realPath = "imgs";
        int expid = Integer.parseInt(req.getParameter("expid"));
        List<ExpImage> images = imageService.findImage(expid);
        List<String> imageSrc = new ArrayList<>();

        for(ExpImage image : images) {
            String src = realPath + "\\" + image.getFilename();
            imageSrc.add(src);
            System.out.println(src);
        }

        req.setAttribute("imageSrc", imageSrc);
        req.getRequestDispatcher("/expenseImg.jsp").forward(req, resp);
    }

}
